package com.spider.demo1inetaddress;

import java.net.InetAddress;

public class InetAdressDemo1 {
    public static void main(String[] args) {
        //目标：认识InetAddress获取本机的IP对象和IP对方IP对象
        try {
            //获取本机的IP对象
            InetAddress ip1 = InetAddress.getLocalHost();
            System.out.println(ip1.getHostName());//本机
            System.out.println(ip1.getHostAddress());

            //获取对方IP对象
            InetAddress ip2 = InetAddress.getByName("www.baidu.com");
            System.out.println(ip2.getHostName());
            System.out.println(ip2.getHostAddress());

            //判断本机与对方主机是否互通
            boolean reachable = ip2.isReachable(5000);
            System.out.println(reachable);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
